<!-- 压力机 -->
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col class="aaa" :span="show ? rowObj.T1 : rowObj.F1" :xs="show ? rowObj.T2 : rowObj.F2">
        <workSiteLeft ref="workSiteLeft" :show="show" @showLeft="showLeft" @queryVal="queryVal" />
      </el-col>
      <el-col :span="show ? rowObj.T3 : rowObj.F3" :xs="show ? rowObj.T4 : rowObj.F4">
        <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="80px" style="display: flex;justify-content: space-between;">
          <div>
            <!-- <el-form-item label="工地名称" prop="id">
              <el-select v-model="queryParams.id" clearable size="mini" placeholder="请选择工地名称">
                <el-option v-for="item in constructionList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item> -->
            <el-button style="margin-right: 6px" size="mini" :icon="show ? 'el-icon-s-fold' : 'el-icon-s-unfold'" circle @click="showLeft(show)"></el-button>
            <el-form-item label="是否合格" prop="eligible">
              <el-select style="width: 100px" v-model="queryParams.eligible" clearable size="mini" placeholder="请选择">
                <el-option v-for="item in eligibleList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="试验时间" prop="id">
              <deatetime ref="deatetime" v-model="queryParams.time"> </deatetime>
            </el-form-item>
            <el-form-item label="试验类型" prop="SYLX">
              <el-select style="width: 120px" v-model="queryParams.SYLX" clearable size="mini" placeholder="请选择">
                <el-option v-for="item in sylxs" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>

              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['laboratoryManage:press:query']">搜索</el-button>
              <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
            </el-form-item>
          </div>
          <div>
            <el-form-item>
              <el-button type="success" icon="el-icon-thumb" size="mini" v-hasPermi="['laboratoryManage:press:collectTest']" :loading="warningLoading" @click="handleCollectData">数据采集测试</el-button>
            </el-form-item>
          </div>
        </el-form>

        <el-table border v-loading="loading" :data="cementDataList" size="mini">
          <el-table-column label="试验名称" align="center" prop="symc" fixed show-overflow-tooltip width="110" />
          <el-table-column label="试验编号" align="center" prop="sybh" width="190" show-overflow-tooltip fixed />
          <!-- <el-table-column label="所属单位" align="center" prop="deptName" show-overflow-tooltip width="110"/> -->
          <el-table-column label="设备名称" align="center" prop="deviceName" show-overflow-tooltip width="130" />
          <el-table-column label="设备型号" align="center" prop="deviceModel" show-overflow-tooltip width="100" />
          <el-table-column label="试样数量" align="center" prop="sysl" width="75" />
          <el-table-column label="龄期" align="center" prop="lq" width="60" />
          <el-table-column label="强度等级" align="center" width="75">
            <template slot-scope="scope"><span>{{ scope.row.qddj || "-" }}</span></template>
          </el-table-column>
          <!-- <el-table-column label="有效力值" align="center" prop="yxlz" width="75" show-overflow-tooltip /> -->
          <el-table-column label="有效强度" align="center" prop="yxqd" width="75" show-overflow-tooltip />
          <el-table-column label="评定结果" align="center" width="75" show-overflow-tooltip>
            <template slot-scope="scope"><span>{{ scope.row.pdjg || "-" }}</span></template>
          </el-table-column>
          <!-- <el-table-column label="是否合格" align="center" width="75">
            <template slot-scope="scope"><span>{{ scope.row.eligible == 1 ? "合格" : (scope.row.eligible == 0 ? "不合格" : "未校验") }}</span></template>
          </el-table-column> -->
          <el-table-column label="试验时间" align="center" prop="sysj" width="135" />
          <el-table-column label="截面形状" align="center" prop="shape" width="75" />
          <el-table-column label="尺寸" align="center" prop="size" width="100" />
          <el-table-column label="系数" align="center" prop="xs" width="60" />

          <el-table-column label="品种" align="center" width="75" show-overflow-tooltip>
            <template slot-scope="scope"><span>{{ scope.row.pinZhong || "-" }}</span></template>
          </el-table-column>
          <el-table-column label="设备编号" align="center" width="90" prop="deviceCode" show-overflow-tooltip />
          <el-table-column label="试验员" align="center" width="75" show-overflow-tooltip>
            <template slot-scope="scope"><span>{{ scope.row.tester || "-" }}</span></template>
          </el-table-column>
          <!-- <el-table-column label="状态" align="center">
            <template slot-scope="scope"><span>{{ scope.row.tag == 0 ? "未完成" : "已完成" }}</span></template>
            状态标记 0:该组试验未完成 1:该组试验完成
          </el-table-column> -->
          <!-- <el-table-column label="评定结果" align="center" width="75" show-overflow-tooltip>
            <template slot-scope="scope"><span>{{ scope.row.pdjg || "-" }}</span></template>
          </el-table-column> -->
          <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="260px">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="handleDetails(scope.row)" v-hasPermi="['laboratoryManage:press:details']">详情</el-button>
              <el-button size="mini" type="text" @click="check(scope.row)" v-hasPermi="['laboratoryManage:press:check']">数据校验</el-button>
              <el-button size="mini" type="text" icon="el-icon-edit" :disabled="scope.row.lq != 28" @click="handleUpdate(scope.row)" v-hasPermi="['laboratoryManage:press:editing']">报表编辑</el-button>
              <el-button size="mini" type="text" icon="el-icon-tickets" :disabled="scope.row.lq != 28" @click="handleReportForms(scope.row)" v-hasPermi="['laboratoryManage:press:preview']">报表预览</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>

    <!-- 详情 -->
    <el-dialog title="详情" :visible.sync="rowDetailsDialog" width="80%">
      <el-table border v-loading="loadingTwo" :data="detailsList" size="mini">
        <el-table-column label="序号" type="index" align="center" width="50" />
        <el-table-column label="截面形状" align="center" width="80">
          <template slot-scope="scope"><span>{{ scope.row.shape || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="尺寸" align="center" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope"><span>{{ scope.row.size || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="强度等级" align="center" min-width="80">
          <template slot-scope="scope"><span>{{ scope.row.qddj || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="品种" align="center" min-width="80" show-overflow-tooltip>
          <template slot-scope="scope"><span>{{ scope.row.pinZhong || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="转换系数" align="center" min-width="80">
          <template slot-scope="scope"><span>{{ scope.row.xs || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="极限荷载(kN)" align="center" min-width="100">
          <template slot-scope="scope"><span>{{ scope.row.load || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="极限强度(Mpa)" align="center" min-width="110">
          <template slot-scope="scope"><span>{{ scope.row.stress || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="试验开始时间" align="center" width="135">
          <template slot-scope="scope"><span>{{ scope.row.testBegin || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="试验结束时间" align="center" width="135">
          <template slot-scope="scope"><span>{{ scope.row.testEnd || "-" }}</span></template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="90">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleForceCurve(scope.row)" v-hasPermi="['laboratoryManage:press:forceCurve']">力值曲线</el-button>

          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="totalTwo > 0" :total="totalTwo" :page.sync="queryParamsTwo.pageNum" :limit.sync="queryParamsTwo.pageSize" @pagination="getDetailsList" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="rowDetailsDialog = false" size="mini">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 报表预览 -->
    <yi-dialog title="报表预览" ref="dialogReportForms" :visible.sync="dialogVisible_report" width="60%" fullscreen isHandle :isConfirm="false" top="10vh">
      <ReportRender ref="ReportRender" class="bbyl"></ReportRender>
      <div slot="more" class="more">
        <el-button class="print" type="primary" icon="el-icon-printer" size="small" @click="print()" v-hasPermi="['laboratoryManage:press:export']">打印/导出</el-button>
      </div>
    </yi-dialog>

    <!-- 报表编辑 ceshi报表 -->
    <yi-dialog title="报表编辑" class="render-dialog" :visible.sync="dialogVisible_reportEdit" width="60%" fullscreen isHandle :isConfirm="false" top="0vh">
    <!-- <yi-dialog title="ceshi报表" class="render-dialog" :visible.sync="dialogVisible_reportEdit" width="80%" fullscreen isHandle :isConfirm="false" top="0vh"> -->
      <div style="width: 930px;height: 300px;margin-left: 70px;">
        <ReportRender v-if="dialogVisible_reportEdit" ref="ReportRender" class="bbbj"></ReportRender>
      </div>
      <div slot="more" class="more">
        <el-button type="primary" size="small" icon="el-icon-picture" @click="save()">保存</el-button>
      </div>
    </yi-dialog>

    <!-- 力值曲线 -->
    <el-dialog title="力值曲线" :visible.sync="forceCurve" width="80%">
      <div class="chartBox">
        <div id="dayChart" style="`width: 100%;height: 500px;transform-origin: 0 0;`"></div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="forceCurve = false" size="mini">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import { deptList } from "@/api/common/common";
import { pressList, pressDetails, pressUpdateList } from "@/api/laboratoryManage/press";
import deatetime from "@/components/Datetime";
import workSiteLeft from "@/views/components/workSiteLeft";
import { verifyEligible } from "@/api/xtcsgl/stressRequires";
import TabsRender from "@/views/ReportDesign/TabsRender/TabsRender";
import ReportRender from "@/views/ReportDesign/components/ReportRender/ReportRender";
import { testCollectData } from "@/api/zhgd/hntManage";

export default {
  name: "press", //压力机
  data() {
    return {
      sylxs:[{id:'TKY',name:'混凝土抗压'},{id:'TKZ',name:'混凝土抗折'}],
      warningLoading: false,
      dialogVisible_report: false,
      dialogVisible_reportEdit: false,
      eligibleList: [
        { id: "0", name: "不合格" },
        { id: "1", name: "合格" },
      ],
      obj:{},
      show: true,
      rowObj: {
        T1: 3,
        T2: 24,
        T3: 21,
        T4: 24,
        F1: 0,
        F2: 0,
        F3: 24,
        F4: 24,
      },
      ysgcsj: null,
      dayChart: null,
      forceCurve: false,
      rowId: "",
      detailsList: [], //详情列表
      queryParamsTwo: {
        pageNum: 1,
        pageSize: 10,
      },
      totalTwo: 0,
      loadingTwo: false,
      constructionList: [], //工地列表
      rowDetailsDialog: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 水稳拌合站数据表格数据
      cementDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  components: {
    deatetime,
    workSiteLeft,
    TabsRender,
    ReportRender
  },
  created() {
    // this.getProjectList();
    this.getList();
  },
  methods: {
    //采集数据测试
    handleCollectData() {
      this.$confirm('正式系统禁止采集数据！', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        customClass:'confirm-model',
        type: 'warning',
      }).then(_ => {
        this.warningLoading = true
        testCollectData('ylj', this.queryParams.id).then(res => {
          this.warningLoading = false
          this.getList()
        }).catch((err) => {
          this.warningLoading = false
          this.getList()
        })
      })
    },
    // /** 查询工地列表 */
    // getProjectList() {
    //   deptList().then((res) => {
    //     this.constructionList = res || [];
    //   });
    // },
    /** 查询水稳拌合站数据列表 */
    getList() {
      this.loading = true;
      pressList(this.queryParams).then((response) => {
        this.cementDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // ???
    // rederOver() {
    //   setTimeout(() => {
    //     const element = this.$refs.dialogReportForms;
    //     element.$el.classList.add("render-report");
    //   }, 0);
    // },
    // 点击报表预览按钮
    handleReportForms(row) {
      this.dialogVisible_report = true;
      this.$nextTick(() => {
        this.$refs.ReportRender.editDataRender("compressive_strength", {
          id: row.id,
          reportId: "1735115888052457474",
          sybh: row.sybh,
        });
      });
    },
    // 点击报表编辑按钮
    handleUpdate(row) {
      this.dialogVisible_reportEdit = true;
      this.$nextTick(() => {
        this.$refs.ReportRender.editInit("compressive_strength", {
          id: row.id,
          reportId: "1735115888052457474",
          sybh: row.sybh,
        });
      });
    },
    // // 报表编辑保存
    // save() {
    //   // 这个代码就是 取 报表设置的参数
    //   var dataBb = this.$refs.ReportRender.editSave()
    //   var arrayParam = dataBb.dataReturn[0].list;
    //   // 处理arrayParam
    //   for(let i = 0; i<arrayParam.length; i++){
    //     if(i % 3 != 0){
    //       arrayParam[i].lq = arrayParam[i-1].lq;
    //     }
    //   }
    //   pressUpdateList(arrayParam).then(response => {
    //     this.$modal.msgSuccess("编辑成功");
    //   }).finally(() => {
    //     this.dialogVisible_reportEdit = false;
    //   })
    // },
    // 报表编辑保存
    save() {
      // 这个代码就是 取 报表设置的参数
      var dataBb = this.$refs.ReportRender.editSave()
      var sjbs = dataBb.dataReturn[1]
      this.obj = {
        bs: {
          projectPartUse: sjbs.projectPartUse,
          sytj: sjbs.sytj,
          mainDeviceNameAndNum: sjbs.mainDeviceNameAndNum,
          hntType: sjbs.hntType,
          stirMode: sjbs.stirMode,
          maintainCondition: sjbs.maintainCondition,
          bl: sjbs.bl,
          designDLD: sjbs.designDLD,
        },
        bos: dataBb.dataReturn[1].list
      }
      var sjbos = this.obj.bos
      // 处理obj
      for(let i = 0; i<sjbos.length; i++){
        if(i % 3 != 0){
          sjbos[i].sctld1 = sjbos[i-1].sctld1;
          sjbos[i].sctld2 = sjbos[i-1].sctld2;
        }
      }
      pressUpdateList(this.obj).then(response => {
        this.$modal.msgSuccess("编辑成功");
      }).finally(() => {
        this.dialogVisible_reportEdit = false;
      })
    },
    // 打印
    print() {
      this.$refs.ReportRender.print();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams = this.getSearchParams();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getSearchParams() {
      const params = {};
      for (const key in this.queryParams) {
        if (key === "time") {
          const time = this.queryParams[key];
          if (time && time.length === 2) {
            params.startTime = time[0];
            params.endTime = time[1];
          }
        } else {
          params[key] = this.queryParams[key];
        }
      }
      return params;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.workSiteLeft.resetQuery();
      this.queryParams.id = "";
      this.$refs.deatetime.startTime = null;
      this.$refs.deatetime.endTime = null;
      this.queryParams.time = [];
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleDetails(row) {
      this.rowId = row.id;
      pressDetails({
        ...this.queryParamsTwo,
        id: row.id,
      }).then((res) => {
        this.detailsList = res.rows;
        this.totalTwo = res.total;
        this.rowDetailsDialog = true;
      });
    },
    getDetailsList() {
      this.loadingTwo = true;
      pressDetails({ ...this.queryParamsTwo, id: this.rowId }).then(
        (response) => {
          this.detailsList = response.rows;
          this.totalTwo = response.total;
          this.loadingTwo = false;
        }
      );
    },
    handleClose() {
      this.$confirm("确认关闭？")
        .then((_) => {
          F;
          done();
        })
        .catch((_) => { });
    },
    handleForceCurve(row) {
      this.forceCurve = true;
      this.ysgcsj = row.ysgcsj;
      let title = "压力机力值曲线";
      if (document.getElementById("dayChart")) {
        this.createDayChart(title, row.ysgcsj);
      } else {
        this.$nextTick(() => {
          this.createDayChart(title, row.ysgcsj);
        });
      }
    },
    createDayChart(title, data) {
      if (null == this.dayChart) {
        // this.dayChart = this.$echarts.init(document.getElementById('dayChart'));
        this.dayChart = echarts.init(document.getElementById("dayChart"));
      } else {
        this.dayChart.clear();
      }
      let xData = [];
      let sData = [];
      if (!!data) {
        let array = data.split(";");
        array.forEach((item) => {
          let dataItem = item.split(",");
          xData.push(dataItem[0]);
          sData.push(dataItem[1]);
        });
      }
      let option = this.getLineOption(title, "时间(秒)", xData, sData);
      this.dayChart.setOption(option);
    },
    /**
     * 获取图表配置信息
     */
    getLineOption(title, xName, xData, sData) {
      let option = {
        title: {
          text: title,
          textStyle: {
            padingLeft: 100,
          },
        },
        tooltip: {
          trigger: "axis",
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          name: xName,
          data: xData,
          axisLine: { onZero: true },
          splitLine: { show: false },
          splitArea: { show: false },
          axisLabel: {
            rotate: 45,
            formatter: (value, index) => {
              return value + "秒";
            },
          },
        },
        yAxis: {
          name: "力值(kN)",
          axisLabel: {
            formatter: (value, index) => {
              if (index == 0) {
                return "";
              }
              return value;
            },
          },
        },
        grid: {
          top: 60,
          bottom: 60,
          left: 60,
          right: 60,
        },
        series: [
          {
            data: sData,
            type: "line",
            smooth: true,
            itemStyle: {
              color: "#409EFF",
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#409EFF",
                },
                {
                  offset: 1,
                  color: "rgba(64,158,255,0)",
                },
              ]),
            },
          },
        ],
      };
      return option;
    },
    showLeft(show) {
      this.show = !show;
    },
    queryVal(val) {
      this.queryParams.id = val.id;
      this.handleQuery();
    },
    check(row) {
      this.$confirm('正式系统禁止手动预警！', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        customClass:'confirm-model',
        type: 'warning',
      }).then(_ => {
        verifyEligible({ id: row.id }).then((res) => {
          if (res.code == 200) {
            this.getList()
            this.$message.success(res.msg);
          } else {
            this.$message.error(res.msg);
          }
        });
      })
    },
  },
};
</script>
<style scoped lang="scss">
.app-press {
  // padding-top: 16px;
  // user-select: none;

  .chartBox {
    height: 350px;
    width: 100%;
    position: relative;
  }

  .chartBoxHeight {
    height: 400px;
    width: 100%;
    position: relative;
  }

  .chartSearch {
    position: absolute;
    top: 0px;
    right: 60px;
  }
}
.bbyl{
  ::v-deep .render-layout .el-table td.el-table__cell .column-edit {
    white-space: normal !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
.bbbj{
  ::v-deep .render-layout .el-table td.el-table__cell .column-edit {
    white-space: normal !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>
<style>
.confirm-model {
  .el-message-box__btns {
    .el-button:nth-child(1) {
      float: right;
    }

    .el-button:nth-child(2) {
      margin-right: 10px;
      /*background-color:#2d8cf0;*/
      /*border-color:#2d8cf0;*/
    }

  }
}

</style>
